package com.gec.zhs.controller;

import com.gec.zhs.annotation.RecordUserMessage;
import com.gec.zhs.entity.dto.TokenUserInfoDto;
import com.gec.zhs.entity.enums.MessageTypeEnum;
import com.gec.zhs.entity.enums.VideoStatusEnum;
import com.gec.zhs.entity.pojo.VideoInfoFilePost;
import com.gec.zhs.entity.pojo.VideoInfoPost;
import com.gec.zhs.entity.query.VideoInfoFilePostQuery;
import com.gec.zhs.entity.query.VideoInfoPostQuery;
import com.gec.zhs.entity.vo.PaginationResultVO;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.VideoInfoFilePostService;
import com.gec.zhs.service.VideoInfoFileService;
import com.gec.zhs.service.VideoInfoPostService;
import com.gec.zhs.service.VideoInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-02-11
 * @description 视频详情
 */
@RestController
@RequestMapping("/videoInfo")
public class VideoInfoController extends ABaseController{

    @Autowired
    private VideoInfoPostService videoInfoPostService;

    @Autowired
    private VideoInfoFilePostService videoInfoFilePostService;

    @Autowired
    private VideoInfoService videoInfoService;

    @ApiOperation("查询视频list")
    @RequestMapping("/loadVideoList")
    public ResponseVO loadVideoList(VideoInfoPostQuery videoInfoPostQuery) {
        videoInfoPostQuery.setOrderBy("v.last_update_time desc");
        //查询数量
        videoInfoPostQuery.setQueryCountInfo(true);
        //视频归属用户
        videoInfoPostQuery.setQueryUserInfo(true);
        PaginationResultVO<VideoInfoPost> resultVO = videoInfoPostService.findListByPage(videoInfoPostQuery);
        return getSuccessResponseVO(resultVO);
    }

    @ApiOperation("审核视频")
    @RequestMapping("/auditVideo")
    @RecordUserMessage(messageType = MessageTypeEnum.SYS)
    public ResponseVO auditVideo(String videoId,String reason,Integer status) {
        videoInfoPostService.auditVideo(videoId, status, reason);

        return getSuccessResponseVO(null);
    }

    @ApiOperation("推荐视频")
    @RequestMapping("/recommendVideo")
    public ResponseVO recommendVideo(String videoId) {
        videoInfoPostService.recommendVideo(videoId);
        return getSuccessResponseVO(null);
    }

    @ApiOperation("删除视频")
    @RequestMapping("/deleteVideo")
    public ResponseVO deleteVideo(String videoId) {
        videoInfoService.deleteVideo(videoId,null);
        return getSuccessResponseVO(null);
    }


    @ApiOperation("获取视频分p")
    @RequestMapping("/loadVideoPList")
    public ResponseVO loadVideoPlist(String videoId) {
        VideoInfoFilePostQuery videoInfoFilePostQuery = new VideoInfoFilePostQuery();
        videoInfoFilePostQuery.setVideoId(videoId);
        videoInfoFilePostQuery.setOrderBy("file_index asc");
        List<VideoInfoFilePost> videoInfoFilePostList = videoInfoFilePostService.findListByParam(videoInfoFilePostQuery);
        return getSuccessResponseVO(videoInfoFilePostList);
    }
}
